﻿using System;
using System.Collections.Generic;
using System.Data.Objects;
using LuxuryResort.Entity;

namespace LuxuryResort.DAO
{
    public class FoodOrderDAO : BaseDAO
    {
        public void Insert(List<Food_Beverage_Order> orders, Guid userId, Guid resortId)
        {
            List<LRMPConnection> cs = GetConnectionString(userId, resortId);
            if (cs.Count > 0)
            {
                using (var context = new LRMPEntities(cs[0].ConnectionString))
                {
                    foreach (Food_Beverage_Order order in orders)
                        context.Food_Beverage_Order.AddObject(order);
                    context.SaveChanges();
                }
            }
        }

        public List<KeyValuePair<string, Food_Beverage_Order>> GetAll(Guid userId, Guid resortId)
        {
            List<LRMPConnection> cs = GetConnectionString(userId, resortId);
            var lst = new List<KeyValuePair<string, Food_Beverage_Order>>();
            foreach (LRMPConnection connection in cs)
            {
                using (var context = new LRMPEntities(connection.ConnectionString))
                {
                    ObjectQuery<Food_Beverage_Order> orders = context.Food_Beverage_Order.Include("Food_Beverage");
                    foreach (Food_Beverage_Order o in orders)
                    {
                        lst.Add(new KeyValuePair<string, Food_Beverage_Order>(connection.ResortName, o));
                    }
                }
            }

            return lst;
        }
    }
}